package com.circle.rest.modular.nt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.circle.rest.core.common.enums.ReadStatus;
import com.circle.rest.modular.nt.dao.ContentMapper;
import com.circle.rest.modular.nt.dao.InboxMapper;
import com.circle.rest.modular.nt.model.Inbox;
import com.circle.rest.modular.nt.service.IInboxService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 通知收件箱 服务实现类
 * </p>
 *
 * @author 赵航
 * @since 2019-04-09
 */
@Service
public class InboxServiceImpl extends ServiceImpl<InboxMapper, Inbox> implements IInboxService {

    @Resource
    private ContentMapper contentMapper;

    /**
     * 设置已读状态并增加阅读数
     *
     * @param inbox
     */
    @Async
    @Override
    public void read(Inbox inbox) {
        //设置已读
        inbox.setIsRead(ReadStatus.READ.getCode());
        inbox.setUpdateTime(LocalDateTime.now());
        this.baseMapper.updateById(inbox);

        //增加阅读量
        contentMapper.addReadNum(inbox.getContentId());
    }
}
